package com.onefinger.manager.mocks
{
	import com.onefinger.manager.vos.Category;
	import com.onefinger.manager.vos.Item;
	import com.onefinger.manager.vos.Subcategory;
	
	import mx.collections.ArrayCollection;

	public class ItemMockService
	{
		private var _list:ArrayCollection = new ArrayCollection();
		
		public function ItemMockService()
		{
			var subcategoryService:SubCategoryMockService = new SubCategoryMockService();
			/*		var wineCategory:Category = new Category();
			wineCategory.id = 1;
			wineCategory.name = "Vinos";
			wineCategory.showOrder = 1;
			wineCategory.icon = "wines.jpg";*/
			var wineItem:Item=new Item();
			wineItem.icon= "wines.jpg";
			wineItem.subcategory=subcategoryService.list().getItemAt(0) as Subcategory;
			wineItem.name ="Vino Toro";
			wineItem.ranking = 25;
			wineItem.shortDescription="uvas de malbec";
			wineItem.showOrder=1;
			
			_list.addItem( wineItem );
		}
		
		
		public function list():ArrayCollection
		{
			return _list;
		}
		
		public function save( item:Item ):Boolean
		{
			var index:int = _list.getItemIndex( item );
			if( index != -1 )
			{
				_list.list.itemUpdated(item);
				return true;
			} else {
				_list.addItem(item);
				return true;
			}
		}
		public function update( item:Item ):Boolean
		{
			var index:int = _list.getItemIndex( item );
			if( index != -1 )
			{
				_list.list.itemUpdated(item);
				return true;
			} else {
				return true;
			}
		}
		public function remove(item:Item):Boolean
		{
			var index:int = _list.getItemIndex( item );
			if( index == -1 )
			{
				return false;
			} else {
				_list.removeItemAt( index );
				return true;
			}
		}
		
	}
}